package com.shujia.hadoop.mr;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

    public class MR06 {
    public static class FilesMapper extends Mapper<LongWritable,Text,Text,NullWritable>{
        @Override
        protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
          context.write (value,NullWritable.get ());
        }
    }
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Job job = Job.getInstance ( );
        job.setNumReduceTasks (0);
        job.setJarByClass (MR06.class);
        job.setMapperClass (FilesMapper.class);
        job.setMapOutputKeyClass (Text.class);
        job.setMapOutputValueClass (NullWritable.class);
        Path input = new Path ("/students.txt");
        FileInputFormat.addInputPath (job,input);
        Path input1 = new Path ("/score.txt");
        FileInputFormat.addInputPath (job,input1);
        Path output = new Path ("/output");
        FileSystem fs = FileSystem.get (new Configuration ( ));
        if (fs.exists (output)){
            fs.delete (output,true);
        }
        FileOutputFormat.setOutputPath (job,output);
        job.waitForCompletion (true);



    }
}
